package com.hrm.controller;



import com.hrm.pojo.DTO.JobPageDTO;
import com.hrm.pojo.Job;
import com.hrm.service.JobService;
import com.hrm.utils.entity.PageResult;
import com.hrm.utils.entity.Result;
import com.hrm.utils.entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/job")
@RestController
@Api(tags = "职位相关接口")
public class JobController {
    @Autowired
    private JobService jobService;

    /**
     * 职位查询
     * @param jobPageDTO
     * @return
     */
    @ApiOperation("职位查询")
    @GetMapping("/page")
    public Result page(JobPageDTO jobPageDTO){
        PageResult<Job> pageJob = jobService.page(jobPageDTO);
        return new Result(pageJob!=null,pageJob!=null? StatusCode.SUCCESS:StatusCode.ERROR,"操作完成",pageJob);
    }

    /**
     * 删除部门
     * @param id
     * @return
     */
    @ApiOperation("删除职位")
    @DeleteMapping("delete/{id}")
    public Result deleteById(@PathVariable Integer id){
        Boolean flag = jobService.deleteById(id);
        return new Result(flag, flag ? StatusCode.SUCCESS : StatusCode.ERROR, "操作完成");
    }

    /**
     * 添加职位
     * @param
     * @return
     */
    @ApiOperation("添加职位")
    @PostMapping("/add")
    public Result addDept(@RequestBody Job job){
        Boolean flag = jobService.insertJob(job);
        return new Result(flag, flag ? StatusCode.SUCCESS : StatusCode.ERROR, "操作完成");
    }

    /**
     * 修改职位
     * @param job
     * @return
     */
    @ApiOperation("修改职位")
    @PutMapping("/update")
    public Result updateDept(@RequestBody Job job){
        Boolean flag = jobService.updateById(job);
        return new Result(flag, flag ? StatusCode.SUCCESS : StatusCode.ERROR, "操作完成");
    }

    /**
     * 获得所有职位信息
     * @return
     */
    @ApiOperation("获得所有职位信息")
    @GetMapping("/options")
    public Result getAllJob(){
        List<Job> jobList = jobService.getAllJob();
        return new Result(jobList!=null, jobList!=null ? StatusCode.SUCCESS : StatusCode.ERROR, "操作完成",jobList);
    }
}
